
#include "VFVNonlinearSystem.h"
#include "VFVProblem.h"

namespace O4 {
	void assembly_reconstruction(EquationSystems& es, const std::string& system_name)
	{
		VFVProblem* p =
			es.parameters.get<VFVProblem*>("_vfv_problem");
		p->assmeblyReconstructionSystem(es, system_name);

	}
}

VFVNonlinearSystem::VFVNonlinearSystem(VFVProblem& vfv_problem, const std::string& name):
	NonlinearSystem(vfv_problem, name),
	_linear_sys(vfv_problem.es().add_system<LinearImplicitSystem>(name+"_linear"))

{
	_linear_sys.attach_assemble_function(O4::assembly_reconstruction);
	vfv_problem.es().reinit();
}

VFVNonlinearSystem::~VFVNonlinearSystem()
{
}

SparseMatrix<Number>& VFVNonlinearSystem::addMatrix(TagID tag)
{
	mooseInfo("VFVNonlinearSystem::addMatrix");
	return NonlinearSystem::addMatrix(tag);
}

void VFVNonlinearSystem::solve()
{
	mooseInfo("VFVNonlinearSystem::solve");
	NonlinearSystem::solve();
	_linear_sys.solve();
	mooseInfo(_linear_sys.n_linear_iterations());
}

void VFVNonlinearSystem::stopSolve()
{
	mooseInfo("VFVNonlinearSystem::stopSolve");
	NonlinearSystem::stopSolve();
}

unsigned int VFVNonlinearSystem::getCurrentNonlinearIterationNumber()
{
	mooseInfo("VFVNonlinearSystem::getCurrentNonlinearIterationNumber");
	return NonlinearSystem::getCurrentNonlinearIterationNumber();
}

void VFVNonlinearSystem::setupFiniteDifferencedPreconditioner()
{
	mooseInfo("VFVNonlinearSystem::setupFiniteDifferencedPreconditioner");
	NonlinearSystem::setupFiniteDifferencedPreconditioner();
}

bool VFVNonlinearSystem::converged()
{
	mooseInfo("VFVNonlinearSystem::converged");
	return NonlinearSystem::converged();
}

NumericVector<Number>& VFVNonlinearSystem::RHS()
{
	mooseInfo("VFVNonlinearSystem::RHS");
	return NonlinearSystem::RHS();
}

NonlinearSolver<Number>* VFVNonlinearSystem::nonlinearSolver()
{
	mooseInfo("VFVNonlinearSystem::nonlinearSolver");
	return NonlinearSystem::nonlinearSolver();
}


TransientNonlinearImplicitSystem& VFVNonlinearSystem::sys()
{
	mooseInfo("VFVNonlinearSystem::sys");
	return NonlinearSystem::sys();
}

//void VFVNonlinearSystem::computeScalingJacobian()
//{
//	mooseInfo("VFVNonlinearSystem::computeScalingJacobian");
//	NonlinearSystem::computeScalingJacobian();
//}
